package com.zhang.apidriver.service.impl;

import com.zhang.apidriver.remote.ServiceOrderClient;
import com.zhang.apidriver.remote.ServiceSsePushClient;
import com.zhang.apidriver.service.PayService;
import com.zhang.internalcommon.constant.IdentityConstant;
import com.zhang.internalcommon.dto.OrderRequest;
import com.zhang.internalcommon.dto.PushRequest;
import com.zhang.internalcommon.dto.ResponseResult;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 类功能描述
 *
 * @author Kye
 * @date 2025-04-20
 */
@Service
public class PayServiceImpl implements PayService {

	@Autowired
	ServiceSsePushClient serviceSsePushClient;

	@Autowired
	ServiceOrderClient serviceOrderClient;

	@Override
	public ResponseResult pushPayInfo(Long orderId, String price, Long passengerId) {
		// 封装消息
		JSONObject message = new JSONObject();
		message.put("price",price);
		message.put("orderId",orderId);
		// 修改订单状态
		OrderRequest orderRequest = new OrderRequest();
		orderRequest.setOrderId(orderId);
		serviceOrderClient.pushPayInfo(orderRequest);

		PushRequest pushRequest = new PushRequest();
		pushRequest.setContent(message.toString());
		pushRequest.setUserId(passengerId);
		pushRequest.setIdentity(IdentityConstant.PASSENGER_IDENTITY);

		// 推送消息
		serviceSsePushClient.push(pushRequest);

		return ResponseResult.success();
	}
}
